package main

import "fmt"

func main() {

	// Slice[T]
	type Slice[T int|float64|float32] []T

	var a Slice[int] = []int{1,2,3,4,5,6,7,8}
	fmt.Println(a)

	var b Slice[float64] = []float64{1.361,2.12345,3.51,4.541,5.981,6.12,7.36,8.946}
	fmt.Println(b)

	var c Slice[float32] = []float32{1.9,2.3,3.4,4.4,5.1,6.5,7.62,8.51}
	fmt.Println(c)

	// 错误，因为变量a的类型为Slice[int] , b 的类型为Slice[float32]
	//a = b

	// 错误，string不在类型约束 中Slice[T int|float64|float32] []T
	//var d Slice[string] = []string{"a","b","c","d","e","f","g","h"}
	//fmt.Println(d)
	//fmt.Printf("type nams: %T:",d)

	// 错误，SLice[T] 是泛型类型，不可以直接使用必须实例化为具体的类型
	//var d Slice[T] = []int{12.9,2,3}

	type MyMap[KEY int|string, VALUE any] map[KEY]VALUE

	var m1 MyMap[string,float64] = map[string]float64{
		"go":9.9,
		"java":9.0,
		"python":10.0,
	}
	fmt.Println(m1)

	//type Wow[T int | string] int
	//
	//var a Wow[int] = 123           // 编译正确
	//var b Wow[string] = 123        // 编译正确
	//var c Wow[string] = "hello"    // 编译错误，因为”hello“ 不能赋值给底层类型int
}
